package be.kuleuven.cs.mop.gui.components;


import java.awt.BorderLayout;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import be.kuleuven.cs.mop.domain.exceptions.TaskManagerException;
import be.kuleuven.cs.mop.domain.model.impl.Schedule;



/**
 * {@link JPanel} implementation for {@link Schedule} input
 */
public class ScheduleInput extends Component implements Input<Schedule> {
	private static final long serialVersionUID = 1L;
	
	private DateInput		deadline	= new DateInput();
	private DurationInput	duration	= new DurationInput();
	private DateInput		start		= new DateInput();
	
	
	public ScheduleInput() {
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		
		add(start,		BorderLayout.NORTH);
		add(duration,	BorderLayout.CENTER);
		add(deadline,	BorderLayout.SOUTH);
	}
	
	
	
	@Override
	public Schedule read() throws TaskManagerException {
		return new Schedule(start.read(), deadline.read(), duration.read());
	}
	
	@Override
	public void write(final Schedule schedule) {
		deadline.set(schedule.getDeadline());
		duration.set(schedule.getDuration());
		start.set(schedule.getStartDate());
	}
	
}